<style lang="less">
@import '../../../styles/table-common.less';
@import '../../personInfo.less';
@import './todoManage.less';

.demo-spin-col {
  height: 100px;
  position: relative;
  border: 1px solid #eee;
}

.demo-spin-icon-load {
  animation: ani-demo-spin 1s linear infinite;
}
</style>

<style lang="less" scoped>
  .w200 {
    width: 200px;
  }
  .ml-35 {
   margin-left: -35px
  }
  .mr16 {
    margin-right: 16px
  }

</style>
<template>
  <div class="search">
    <historicDetail v-if="showHistory" @close="showHistory = false" :idCard="idCard" :type="historyType"/>
    <Row :gutter="16" class="all-height" v-else>
      <Col :span="showRight ? 18 : 24" class="all-height">
        <Card class="all-height card-child-height">
          <Row class="operation code-row-bg" style="display: flex; justify-content: space-between">
            <Col span="22">
              <Button @click="passAllTask" icon="md-checkmark-circle-outline">批量通过</Button>
              <!--              <Button @click="noPassAllTask" icon="md-close">批量不通过</Button>-->
              <Button @click="backAllTask" icon="md-return-left">批量驳回</Button>
              <Button @click="getDataList" icon="md-refresh">刷新</Button>
              <!--        <Button type="dashed" @click="openSearch = !openSearch">{{-->
              <!--          openSearch ? "关闭搜索" : "开启搜索"-->
              <!--        }}</Button>-->
              <Button type="dashed" @click="openTip = !openTip">{{ openTip ? '关闭提示' : '开启提示' }}</Button>
            </Col>
            <Col span="2" style="text-align: right">
              <Icon
                  color="#fff"
                  style="background: rgb(45, 154, 244); border-radius: 50%; padding: 3px"
                  :type="showRight ? `ios-arrow-forward` : `ios-arrow-back`"
                  @click.native="clickShowRight"
              ></Icon>
              <!--              <Button-->
              <!--                  :icon="showRight?`ios-arrow-forward`:`ios-arrow-back`"-->
              <!--                  @click.native="clickShowRight"-->
              <!--                  size="mini"-->
              <!--                  type="primary">-->
              <!--              </Button>-->
            </Col>
          </Row>
          <Row v-show="openTip">
            <Alert show-icon>
              已选择
              <span class="select-count">{{ selectList.length }}</span>
              项
              <a class="select-clear" @click="clearSelectAll">清空</a>
            </Alert>
          </Row>
          <Row class="calc-px-height">
            <div v-if="loading" class="wh-100 d-flex-around-center">
              <Spin></Spin>
            </div>
            <div v-else v-ref-height="refHeight" class="wh-100">
              <Table
                  v-if="data.length > 0"
                  :height="refHeight.value"
                  border
                  :columns="columns"
                  sortable="custom"
                  :data="data"
                  @on-sort-change="changeSort"
                  @on-selection-change="showSelect"
                  ref="table"
              ></Table>
              <div v-else class="wh-100">
                <NoData class="wh-100"></NoData>
              </div>
            </div>
          </Row>
          <Row type="flex" justify="end" class="page">
            <Page
                :current="searchForm.pageNumber"
                :total="total"
                :page-size="searchForm.pageSize"
                @on-change="changePage"
                @on-page-size-change="changePageSize"
                :page-size-opts="[10, 20, 50, 100, 200]"
                size="small"
                show-total
                show-elevator
                show-sizer
            ></Page>
          </Row>
        </Card>
      </Col>
      <Col span="6" class="all-height" v-if="showRight">
        <Card class="all-height card-child-height">
          <Row v-show="!modalTaskVisible" @keydown.enter.native="handleSearch">
            <Col span="24">
              <div class="drawer-header">
                <div style="margin-right: 16px">查询区</div>
              </div>
            </Col>
            <Form ref="searchForm" :model="searchForm" :label-width="quryLabelWidth" class="marginForm">
              <FormItem label="学号" prop="xh">
                  <Input type="text" v-model="searchForm.xh" placeholder="请输入" clearable/>
              </FormItem>
              <FormItem label="考生号" prop="xh">
                  <Input type="text" v-model="searchForm.ksh" placeholder="请输入" clearable/>
              </FormItem>
              <FormItem label="身份证号" prop="xh">
                  <Input type="text" v-model="searchForm.idCard" placeholder="请输入" clearable/>
              </FormItem>
              <FormItem label="学生姓名" prop="applyer">
                  <Input type="text" v-model="searchForm.xm" placeholder="请输入" clearable/>
              </FormItem>
              <FormItem label="学校名称" prop="xxmc">
                  <Input type="text" v-model="searchForm.xxmc" placeholder="请输入" clearable/>
              </FormItem>

              <FormItem label="院系名称" prop="yxmc">
                  <Input type="text" v-model="searchForm.yxmc" placeholder="请输入" clearable/>
              </FormItem>
              <FormItem label="单位类别" prop="gzzwlb">
                  <Select v-model="searchForm.gzzwlb" clearable filterable>
                      <Option v-for="(item,index) in gzzwlbList" :value="item.value" :key="index">{{ item.title }}</Option>
                  </Select>
              </FormItem>
              <FormItem label="单位名称" prop="dwmc">
                <Input type="text" v-model="searchForm.dwmc" placeholder="请输入单位名称" clearable />
              </FormItem>
              <FormItem label="单位行业" prop="dwhy">
                  <Select v-model="searchForm.dwhy" clearable filterable>
                      <Option v-for="(item,index) in dwhyList" :value="item.value" :key="index">{{ item.title }}</Option>
                  </Select>
              </FormItem>
              <FormItem label="就业状况" prop="jyzk">
                  <Select v-model="searchForm.jyzk" clearable transfer>
                  <Option value="5">暂未登记或上报</Option>
                      <Option v-for="item in oneTypeDicts" :value="item.value">{{ item.title }}</Option>
                      <Option v-for="(item,index) in oneTypeDicts" :value="item.value" :key="index">{{ item.title }}</Option>

                  </Select>
              </FormItem>
              <!--              <FormItem label="当前审核环节" prop="name">-->
              <!--                <Input-->
              <!--                    type="text"-->
              <!--                    v-model="searchForm.name"-->
              <!--                    placeholder="请输入"-->
              <!--                    clearable-->
              <!--                   -->
              <!--                />-->
              <!--              </FormItem>-->

              <!--              <FormItem label="创建时间">-->
              <!--                <DatePicker-->
              <!--                    :options="options"-->
              <!--                    v-model="selectDate"-->
              <!--                    type="daterange"-->
              <!--                    format="yyyy-MM-dd"-->
              <!--                    clearable-->
              <!--                    @on-change="selectDateRange"-->
              <!--                    placeholder="选择起始时间"-->
              <!--                   -->
              <!--                ></DatePicker>-->
              <!--              </FormItem>-->
                <FormItem class="br box-key">
                <Button @click="handleSearch" type="primary" icon="ios-search">搜索</Button>
                <Button @click="handleReset">重置</Button>
              </FormItem>
            </Form>
          </Row>
          <Row v-show="modalTaskVisible" style="flex-direction: column">
            <div class="drawer-header">
              <div class="mr16">{{ modalTaskTitle }}</div>
            </div>
            <Form ref="form" :model="form" :label-width="quryLabelWidth2" :rules="formValidate" class="marginForm" inline>
              <FormItem label="审核意见" prop="reason">
                <Input type="textarea" v-model="form.comment" :rows="4" maxlength="50" show-word-limit/>
              </FormItem>
              <!--        <FormItem-->
              <!--          label="下一审核人"-->
              <!--          prop="assignees"-->
              <!--          v-show="showAssign"-->
              <!--          :error="error"-->
              <!--        >-->
              <!--          <Select-->
              <!--            v-model="form.assignees"-->
              <!--            placeholder="请选择或输入搜索"-->
              <!--            filterable-->
              <!--            clearable-->
              <!--            multiple-->
              <!--            :loading="userLoading"-->
              <!--          >-->
              <!--            <Option-->
              <!--              v-for="(item, i) in assigneeList"-->
              <!--              :key="i"-->
              <!--              :value="item.id"-->
              <!--              :label="item.nickname"-->
              <!--            >-->
              <!--              <span style="margin-right: 10px">{{ item.nickname }}</span>-->
              <!--              <span style="color: #ccc">{{ item.username }}</span>-->
              <!--            </Option>-->
              <!--          </Select>-->
              <!--        </FormItem>-->
              <!--        <FormItem-->
              <!--          label="自定义搜索选择审核人"-->
              <!--          prop="assignees"-->
              <!--          v-show="isCustom"-->
              <!--          :error="error"-->
              <!--        >-->
              <!--          <Select-->
              <!--            v-model="form.assignees"-->
              <!--            placeholder="请输入用户名搜索选择用户"-->
              <!--            filterable-->
              <!--            remote-->
              <!--            multiple-->
              <!--            :remote-method="searchUser"-->
              <!--            :loading="userLoading"-->
              <!--          >-->
              <!--            <Option-->
              <!--              v-for="(item, i) in userList"-->
              <!--              :value="item.id"-->
              <!--              :key="i"-->
              <!--              :label="item.nickname"-->
              <!--            >-->
              <!--              <span style="margin-right: 10px">{{ item.nickname }}</span>-->
              <!--              <span style="color: #ccc">{{ item.username }}</span>-->
              <!--            </Option>-->
              <!--          </Select>-->
              <!--        </FormItem>-->
              <!--        <FormItem label="下一审核人" v-show="isGateway">-->
              <!--          <span-->
              <!--            >分支网关处暂不支持自定义选择下一审核人，将发送给下一节点所有人</span-->
              <!--          >-->
              <!--        </FormItem>-->
              <div v-show="form.type == 1">
                <!--                <FormItem label="驳回至">-->
                <!--                  <Select-->
                <!--                      v-model="form.backTaskKey"-->
                <!--                      filterable-->
                <!--                      :loading="backLoading"-->
                <!--                      @on-change="changeBackTask"-->
                <!--                  >-->
                <!--                    <Option-->
                <!--                        v-for="(item, i) in backList"-->
                <!--                        :key="i"-->
                <!--                        :value="item.key"-->
                <!--                    >{{ item.name }}</Option-->
                <!--                    >-->
                <!--                  </Select>-->
                <!--                </FormItem>-->
                <!--                <FormItem-->
                <!--                    label="指定原节点审核人"-->
                <!--                    prop="assignees"-->
                <!--                    v-show="form.backTaskKey != -1"-->
                <!--                    :error="error"-->
                <!--                >-->
                <!--                  <Select-->
                <!--                      v-model="form.assignees"-->
                <!--                      placeholder="请选择或输入搜索"-->
                <!--                      filterable-->
                <!--                      clearable-->
                <!--                      multiple-->
                <!--                      :loading="userLoading"-->
                <!--                  >-->
                <!--                    <Option-->
                <!--                        v-for="(item, i) in assigneeList"-->
                <!--                        :key="i"-->
                <!--                        :value="item.id"-->
                <!--                        :label="item.nickname"-->
                <!--                    >-->
                <!--                      <span style="margin-right: 10px">{{ item.nickname }}</span>-->
                <!--                      <span style="color: #ccc">{{ item.username }}</span>-->
                <!--                    </Option>-->
                <!--                  </Select>-->
                <!--                </FormItem>-->
              </div>
              <FormItem label="选择转办人" prop="userId" :error="error" v-show="form.type == 2">
                <Select v-model="form.userId" placeholder="请输入用户名搜索选择用户" filterable remote
                        :remote-method="searchUser"
                        :loading="userLoading">
                  <Option v-for="(item, i) in userList" :value="item.id" :key="i" :label="item.nickname">
                    <span style="margin-right: 10px">{{ item.nickname }}</span>
                    <span style="color: #ccc">{{ item.username }}</span>
                  </Option>
                </Select>
              </FormItem>
              <FormItem label="消息通知">
                <Checkbox v-model="form.sendMessage">站内消息通知</Checkbox>
                <!--          <Checkbox v-model="form.sendSms">短信通知</Checkbox>-->
                <!--          <Checkbox v-model="form.sendEmail">邮件通知</Checkbox>-->
              </FormItem>
            </Form>
            <div class="br right-bottom-edit">
              <Button type="text" @click="modalTaskVisible = false">取消</Button>
              <Button type="primary" :loading="submitLoading" @click="handelSubmit">提交</Button>
            </div>
          </Row>
        </Card>
      </Col>
    </Row>

    <!-- 审核操作 -->
    <!--    <Modal-->
    <!--      :title="modalTaskTitle"-->
    <!--      v-model="modalTaskVisible"-->
    <!--      :mask-closable="false"-->
    <!--      :width="500"-->
    <!--    >-->

    <!--    </Modal>-->

    <!-- 批量审核操作 -->
    <Modal :title="modalTitle" v-model="modalVisible" :mask-closable="false" :width="500">
      <!--      <Alert show-icon>{{-->
      <!--        modalType == 0-->
      <!--          ? "注意：将默认分配给节点设定的所有可审核用户"-->
      <!--          : "注意：所有流程将驳回至发起人"-->
      <!--      }}</Alert>-->
      <Form ref="form" :model="form" :label-width="85" :rules="formValidate">
        <FormItem label="审核意见" prop="reason">
          <Input type="textarea" v-model="form.comment" :rows="4"/>
        </FormItem>
        <FormItem label="消息通知">
          <Checkbox v-model="form.sendMessage">站内消息通知</Checkbox>
          <!--          <Checkbox v-model="form.sendSms">短信通知</Checkbox>-->
          <!--          <Checkbox v-model="form.sendEmail">邮件通知</Checkbox>-->
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="text" @click="modalVisible = false">取消</Button>
        <Button type="primary" :loading="submitLoading" @click="handelSubmitAll">提交</Button>
      </div>
    </Modal>
  </div>
</template>

<script>
import {
  todoList,
  pass,
  noPass,
  back,
  getBackList,
  backToTask,
  delegate,
  getNextNode,
  getNode,
  passAll,
  noPassAll,
  backAll
} from '@/api/activiti';
import {searchUserByName, getDictDataByType} from '@/api/index';
import historicDetail from '../historic-detail/historicDetail.vue';
import {shortcuts} from '@/libs/shortcuts';
import {obtainEmploymentStatusDataAPI} from '@/api/bys/index.js';
import NoData from '@/components/NoData.vue';

export default {
  name: 'todo-manage',
  components: {
    historicDetail,
    NoData
  },
  data() {
    return {
      quryLabelWidth: 70,
      quryLabelWidth2: 85,
      gzzwlbList: [],
      dwhyList: [],
      modalVisible: false,
      modalType: 0,
      showHistory: false,
      procInstId: '',
      idCard: '',
      tableId: '',
      historyType: '',
      openSearch: true,
      openTip: true,
      loading: true, // 表单加载状态
      modalTaskVisible: false,
      userLoading: false,
      backLoading: false,
      userList: [],
      selectList: [], // 多选数据
      assigneeList: [],
      backList: [
        {
          key: '-1',
          name: '发起人'
        }
      ],
      error: '',
      showAssign: false,
      height1: 0,
      refHeight: {value: 0},
      searchForm: {
        // 搜索框对应data对象
        name: '',
        pageNumber: 1, // 当前页数
        pageSize: 50 // 页面大小
      },
      selectDate: null,
      options: {
        shortcuts: shortcuts
      },
      modalTaskTitle: '',
      modalTitle: '', // 添加或编辑标题
      form: {
        id: '',
        userId: '',
        procInstId: '',
        comment: '',
        type: 0,
        assignees: [],
        backTaskKey: '-1',
        sendMessage: true,
        sendSms: false,
        sendEmail: false
      },
      formValidate: {
        // 表单验证规则
      },
      submitLoading: false, // 添加或编辑提交状态
      columns: [],
      columns_1: [
        // 表头
        {
          type: 'selection',
          width: 60,
          align: 'center'
        },
        {
          type: 'index',
          title: '序号',
          width: 80,
          align: 'center'
        },
        {
          title: '学校名称',
          key: 'xxmc',
          minWidth: 180
        },
        {
          title: '院系名称',
          key: 'yxmc',
          minWidth: 120
        },
        {
          title: '专业',
          key: 'zy',
          minWidth: 120
        },
        {
          title: '学生姓名',
          key: 'applyer',
          minWidth: 100,
          align: 'center'
        },
        {
          title: '学号',
          key: 'xh',
          minWidth: 140
        },
        {
          title: '考生号',
          key: 'ksh',
          minWidth: 150
        },
        {
          title: '身份证号',
          key: 'idCard',
          minWidth: 180
        },
        {
          title: '就业状况',
          key: 'jyzk',
          minWidth: 130,
          render: (h, params) => {
            let dict = this.oneTypeDicts.find(item => item.value == params.row.jyzk).title;
            return h('div', dict ? dict : '');
          }
        },
        {
          title: '单位名称',
          key: 'dwmc',
          minWidth: 250,
          sortable: false
        },
        {
          title: '单位行业',
          key: 'dwhy',
          minWidth: 280,
          sortable: false,
          render: (h, params) => {
            let arr = this.dwhyList.filter(e => e.value == params.row.dwhy);
            return h('span', arr && arr.length > 0 ? arr[0].title : '');
          }
        },
        {
          title: '工作职位类别',
          key: 'gzzwlb',
          minWidth: 180,
          sortable: false,
          render: (h, params) => {
            let arr = this.gzzwlbList.filter(e => e.value == params.row.gzzwlb);
            return h('span', arr && arr.length > 0 ? arr[0].title : '');
          }
        },
        {
          title: '申请时间',
          key: 'applyTime',
          minWidth: 160
        },
        {
          title: '当前审核环节',
          key: 'name',
          minWidth: 120,
          tooltip: true
        },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          width: 260,
          fixed: 'right',
          render: (h, params) => {
            let passBtn;
            if (this.btnLoding) {
              passBtn = h(
                  'Spin',
                  {
                    style: {
                      display: 'inline-block'
                    }
                  },
                  [
                    h('Icon', {
                      props: {
                        type: 'ios-loading',
                        size: 12
                      },
                      style: {
                        animation: ' ani-demo-spin 1s linear infinite',
                        display: 'inline-block'
                      }
                    }),
                    h('a', '通过')
                  ]
              );
            } else {
              passBtn = h(
                  'a',
                  {
                    on: {
                      click: () => {
                        this.passTask(params.row);
                      }
                    }
                  },
                  '通过'
              );
            }

            return h('div', [
              h(
                  'a',
                  {
                    on: {
                      click: () => {
                        this.detail(params.row);
                      }
                    }
                  },
                  '详情'
              ),
              h('Divider', {
                props: {
                  type: 'vertical'
                }
              }),
              passBtn,
              // h("Divider", {
              //   props: {
              //     type: "vertical",
              //   },
              // }),
              // h(
              //     "a",
              //     {
              //       on: {
              //         click: () => {
              //           this.noPassTask(params.row);
              //         },
              //       },
              //     },
              //     "不通过"
              // ),
              h('Divider', {
                props: {
                  type: 'vertical'
                }
              }),
              h(
                  'a',
                  {
                    on: {
                      click: () => {
                        this.backTask(params.row);
                      }
                    }
                  },
                  '驳回'
              ),
              // h("Divider", {
              //   props: {
              //     type: "vertical",
              //   },
              // }),
              // h(
              //   "a",
              //   {
              //     on: {
              //       click: () => {
              //         this.delegateTask(params.row);
              //       },
              //     },
              //   },
              //   "转办"
              // ),
              h('Divider', {
                props: {
                  type: 'vertical'
                }
              }),
              h(
                  'a',
                  {
                    on: {
                      click: () => {
                        this.history(params.row);
                      }
                    }
                  },
                  '历史'
              )
            ]);
          }
        }
      ],
      data: [], // 表单数据
      total: 0, // 表单数据总数
      dictPriority: [],
      isGateway: false,
      isCustom: false,
      showRight: true,
      oneTypeDicts: [],
      btnLoding: false
    };
  },
  methods: {
    tableheig() {
      var bbb = document.getElementsByClassName('calc-px-height')[0].scrollHeight;
      var aaa = document.getElementsByClassName('calc-px-height')[0].children[0].children[0].children[1];
      var ccc = document.getElementsByClassName('calc-px-height')[0].children[0].children[0].children[0].scrollHeight;
      var ddd = bbb - ccc;
      console.log(bbb, '00000000000000');
      aaa.style.height = `${ddd}px`;

      if (this.searchForm.pageSize === 10) {
        this.height1 = 0;
      } else {
        this.height1 = document.getElementsByClassName('calc-px-height')[0].scrollHeight;
        if (this.total < this.searchForm.pageNumber * this.searchForm.pageSize) {
          var r = (this.searchForm.pageNumber - 1) * this.searchForm.pageSize;
          var a = this.total - r;
          var s = a * 43 + 65;
          if (s < this.height1) {
            this.height1 = 0;
          }
        }
      }
      if (this.total < 10) {
        this.height1 = 0;
      }
    },
    init() {
      this.getDictDataType();
      if (this.$route.name == 'jyqxsh') {
        this.searchForm.type = 'qx';
      }
      this.getDataList();
    },
    // 显示隐藏右侧区域
    clickShowRight() {
      this.showRight = !this.showRight;
    },

    getDictDataType() {
      getDictDataByType('priority').then(res => {
        if (res.success) {
          this.dictPriority = res.result;
        }
      });
      // 工作职位类别
      getDictDataByType('job-position-category').then(res => {
        if (res.success) {
          this.gzzwlbList = res.result;
        }
      });
      // 单位行业
      getDictDataByType('unit-industry').then(res => {
        if (res.success) {
          this.dwhyList = res.result;
        }
      });
      //
      // getDictDataByType("where-manage-type").then(res => {
      //   if (res.success) {
      //     this.oneTypeDicts = res.result;
      //   }
      // })
      //毕业生就业状况
      obtainEmploymentStatusDataAPI()
          .then(res => {
            this.oneTypeDicts = res.result || [];
          })
          .catch(e => {
            console.log(e);
          });
    },
    searchUser(v) {
      if (!v) {
        return;
      }
      this.userLoading = true;
      searchUserByName(v).then(res => {
        this.userLoading = false;
        if (res.success) {
          this.userList = res.result;
        }
      });
    },
    changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
      if (e.order == 'normal') {
        this.searchForm.order = '';
      }
      this.getDataList();
    },
    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getDataList();
      this.clearSelectAll();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.getDataList();
    },
    selectDateRange(v) {
      if (v) {
        this.searchForm.startDate = v[0];
        this.searchForm.endDate = v[1];
      }
    },
    getDataList() {
      this.loading = true;
      todoList(this.searchForm).then(res => {
        this.loading = false;
        if (res.success) {
          console.log("去向审核", res)
          this.data = res.result.result;
          // this.data = res.result.content;
          this.total = res.result.total;
          // this.tableheig();
          // if (this.data.length == 0 && this.searchForm.pageNumber > 1) {
          //   this.searchForm.pageNumber -= 1;
          //   this.getDataList();
          // }
        }
      });
    },
    handleSearch() {
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 50;
      this.getDataList();
    },
    handleReset() {
      this.$refs.searchForm.resetFields();
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 50;
      this.selectDate = null;
      this.searchForm.startDate = '';
      this.searchForm.endDate = '';
      // 重新加载数据
      this.getDataList();
    },
    showSelect(e) {
      this.selectList = e;
    },
    clearSelectAll() {
      this.$refs.table.selectAll(false);
    },
    handelSubmit() {
      this.submitLoading = true;
      if (this.form.type == 0) {
        // 通过
        if ((this.showAssign || this.isCustom) && this.form.assignees.length < 1) {
          this.error = '请至少选择一个审核人';
          this.submitLoading = false;
          return;
        } else {
          this.error = '';
        }
        pass(this.form).then(res => {
          this.submitLoading = false;
          if (res.success) {
            this.$Message.success('操作成功');
            this.modalTaskVisible = false;
            this.getDataList();
          }
        });
      } else if (this.form.type == 1) {
        // 驳回
        // if (this.form.backTaskKey == "-1") {
        // 驳回至发起人
        back(this.form).then(res => {
          this.submitLoading = false;
          if (res.success) {
            this.$Message.success('操作成功');
            this.modalTaskVisible = false;
            this.getDataList();
          }
        });
        // } else {
        //   // 自定义驳回
        //   if (this.form.backTaskKey != "-1" && this.form.assignees.length < 1) {
        //     this.error = "请至少选择一个审核人";
        //     this.submitLoading = false;
        //     return;
        //   } else {
        //     this.error = "";
        //   }
        //   backToTask(this.form).then((res) => {
        //     this.submitLoading = false;
        //     if (res.success) {
        //       this.$Message.success("操作成功");
        //       this.modalTaskVisible = false;
        //       this.getDataList();
        //     }
        //   });
        // }
      } else if (this.form.type == 2) {
        // 转办
        if (!this.form.userId) {
          this.error = '请搜索选择一转办人';
          this.submitLoading = false;
          return;
        } else {
          this.error = '';
        }
        delegate(this.form).then(res => {
          this.submitLoading = false;
          if (res.success) {
            this.$Message.success('操作成功');
            this.modalTaskVisible = false;
            this.getDataList();
          }
        });
      } else if (this.form.type == 3) {
        // 不通过
        if (this.form.backTaskKey == '-1') {
          noPass(this.form).then(res => {
            this.submitLoading = false;
            if (res.success) {
              this.$Message.success('操作成功');
              this.modalTaskVisible = false;
              this.getDataList();
            }
          });
        }
      }
    },
    detail(v) {
      console.log(v);
      let query = {
        id: v.tableId,
        type: '3',
        backRoute: this.$route.name,
        applyId: v.applyerUserid,
        jyId: v.jyId,
        tId: v.id,
        procInstId: v.procInstId
      };
      this.$router.push({
        name: 'jyqx',
        query: query
      });
    },
    passTask(v) {
      this.modalTaskTitle = '审核通过';
      this.showRight = true;
      this.form.id = v.id;
      this.form.procInstId = v.procInstId;
      this.form.priority = v.priority;
      this.form.type = 0;
      this.form.applyerUserid = v.applyerUserid;
      this.modalTaskVisible = true;


      // this.loading = true;
      // getNextNode(v.procDefId, v.key, v.applyerUserid).then(res => {
      //   this.loading = false;
      //   this.userLoading = false;
      //   if (res.success) {
      //     if (res.result.users != null && res.result.users.length < 1) {
      //       // this.$Message.error("学校无审核人员,请联系学校管理员")
      //       this.$Message.error({
      //         content: '学校无审核人员,请联系学校管理员',
      //         duration: 5,
      //         closable: true
      //       });
      //       return;
      //     }
      //     this.modalTaskTitle = '审核通过';
      //     this.showRight = true;
      //     this.form.id = v.id;
      //     this.form.procInstId = v.procInstId;
      //     this.form.priority = v.priority;
      //     this.form.type = 0;
      //     this.form.applyerUserid = v.applyerUserid;
      //     this.modalTaskVisible = true;
      //     this.userLoading = true;
      //     this.error = '';
      //     if (res.result.type == 3 || res.result.type == 4) {
      //       this.isGateway = true;
      //       this.showAssign = false;
      //       this.isCustom = false;
      //       return;
      //     }
      //     if (res.result.type == 5) {
      //       this.isCustom = true;
      //       this.isGateway = false;
      //       this.showAssign = false;
      //       return;
      //     }
      //     if (res.result.type == 1) {
      //       this.showAssign = true;
      //       this.isGateway = false;
      //       this.isCustom = false;
      //       if (res.result.users && res.result.users.length > 0) {
      //         this.assigneeList = res.result.users;
      //         // 默认勾选
      //         let ids = [];
      //         res.result.users.forEach(e => {
      //           ids.push(e.id);
      //         });
      //         this.form.assignees = ids;
      //         this.showAssign = true;
      //       } else {
      //         this.form.assignees = [];
      //         this.showAssign = false;
      //       }
      //     }
      //   }
      // });
    },
    // changeBackTask(v) {
    //   if (v == "-1") {
    //     return;
    //   }
    //   this.userLoading = true;
    //   getNode(v, {taskId: this.form.id}).then((res) => {
    //     this.userLoading = false;
    //     if (res.success) {
    //       if (res.result.users && res.result.users.length > 0) {
    //         this.assigneeList = res.result.users;
    //         // 默认勾选
    //         let ids = [];
    //         res.result.users.forEach((e) => {
    //           ids.push(e.id);
    //         });
    //         this.form.assignees = ids;
    //       }
    //     }
    //   });
    // },

    backTask(v) {
      this.modalTaskTitle = '审核驳回';
      this.showRight = true;
      this.form.id = v.id;
      this.form.procInstId = v.procInstId;
      this.form.procDefId = v.procDefId;
      this.form.priority = v.priority;
      this.form.type = 1;
      this.showAssign = false;
      this.isCustom = false;
      this.modalTaskVisible = true;
      // 获取可驳回节点
      this.backList = [
        {
          key: '-1',
          name: '发起人'
        }
      ];
      this.form.backTaskKey = '-1';
      // this.backLoading = true;
      //暂时注掉
      // getBackList(v.procInstId).then((res) => {
      //   this.backLoading = false;
      //   if (res.success) {
      //     res.result.forEach((e) => {
      //       this.backList.push(e);
      //     });
      //   }
      // });
    },
    noPassTask(v) {
      this.modalTaskTitle = '审核不通过';
      this.showRight = true;
      this.form.id = v.id;
      this.form.procInstId = v.procInstId;
      this.form.procDefId = v.procDefId;
      this.form.priority = v.priority;
      this.form.type = 3;
      this.showAssign = false;
      this.isCustom = false;
      this.modalTaskVisible = true;
      // 获取可驳回节点
      this.backList = [
        {
          key: '-1',
          name: '发起人'
        }
      ];
      this.form.backTaskKey = '-1';
      // this.backLoading = true;
      //暂时注掉
      // getBackList(v.procInstId).then((res) => {
      //   this.backLoading = false;
      //   if (res.success) {
      //     res.result.forEach((e) => {
      //       this.backList.push(e);
      //     });
      //   }
      // });
    },
    delegateTask(v) {
      this.modalTaskTitle = '委托他人代办';
      this.form.id = v.id;
      this.form.procInstId = v.procInstId;
      this.form.type = 2;
      this.showAssign = false;
      this.isCustom = false;
      this.modalTaskVisible = true;
    },
    history(v) {
      console.log(v, 'vvvv');
      if (!v.applyerUserid) {
        // this.$Message.error("流程实例ID不存在");
        this.$Message.error({
          content: '流程实例ID不存在',
          duration: 5,
          closable: true
        });
        return;
      }
      this.idCard = v.idCard;
      this.tableId = v.tableId;
      this.historyType = '1';
      this.showHistory = true;
    },
    passAllTask() {
      if (this.selectList.length <= 0) {
        this.$Message.warning('您还未选择要通过的数据');
        return;
      }
      // 批量通过
      this.modalVisible = true;
      this.modalType = 0;
      this.modalTitle = '批量通过 ' + this.selectList.length + ' 条数据';
    },
    noPassAllTask() {
      if (this.selectList.length <= 0) {
        this.$Message.warning('您还未选择要不通过的数据');
        return;
      }
      // 批量不通过
      this.modalVisible = true;
      this.modalType = 2;
      this.modalTitle = '批量不通过' + this.selectList.length + ' 条数据';
    },
    backAllTask() {
      if (this.selectList.length <= 0) {
        this.$Message.warning('您还未选择要驳回的数据');
        return;
      }
      // 批量驳回
      this.modalVisible = true;
      this.modalType = 1;
      this.modalTitle = '批量驳回 ' + this.selectList.length + ' 条数据';
    },
    handelSubmitAll() {
      this.submitLoading = true
      if (this.modalType == 0) {
        let ids = '';
        let applyerUserids = '';
        let params = {};
        this.selectList.forEach(function (e) {
          ids += e.id + ',';
          applyerUserids += e.applyerUserid + ',';
        });
        ids = ids.substring(0, ids.length - 1);
        params = {
          ids: ids,
          applyerUserids: applyerUserids,
          comment: this.form.comment,
          sendMessage: this.form.sendMessage,
          sendSms: this.form.sendSms,
          sendEmail: this.form.sendEmail
        };
        passAll(params).then(res => {
          this.$Modal.remove();
          if (res.success) {
            this.$Message.info(res.message);
            this.modalVisible = false;
            this.clearSelectAll();
            this.getDataList();
            this.submitLoading = false
          } else {
            this.$Message.info(res.message);
            this.submitLoading = false
          }
        });
      } else if (this.modalType == 2) {
        let procInstIds = '',
            params = {};
        this.selectList.forEach(function (e) {
          procInstIds += e.procInstId + ',';
        });
        procInstIds = procInstIds.substring(0, procInstIds.length - 1);
        params = {
          procInstIds: procInstIds,
          comment: this.form.comment,
          sendMessage: this.form.sendMessage,
          sendSms: this.form.sendSms,
          sendEmail: this.form.sendEmail
        };
        noPassAll(params).then(res => {
          this.$Modal.remove();
          if (res.success) {
            this.$Message.success('操作成功');
            this.modalVisible = false;
            this.clearSelectAll();
            this.getDataList();
            this.submitLoading = false

          } else {
            this.$Message.info(res.message);
            this.submitLoading = false
          }
        });
      } else {
        let procInstIds = '',
            params = {};
        this.selectList.forEach(function (e) {
          procInstIds += e.procInstId + ',';
        });
        procInstIds = procInstIds.substring(0, procInstIds.length - 1);
        params = {
          procInstIds: procInstIds,
          comment: this.form.comment,
          sendMessage: this.form.sendMessage,
          sendSms: this.form.sendSms,
          sendEmail: this.form.sendEmail
        };
        backAll(params).then(res => {
          this.$Modal.remove();
          if (res.success) {
            this.$Message.success('操作成功');
            this.modalVisible = false;
            this.clearSelectAll();
            this.getDataList();
            this.submitLoading = false
          } else {
            this.$Message.info(res.message);
            this.submitLoading = false
          }
        });
      }
     
    },
    onRestWindow() {
      this.columns = this.restTableCellWidth(this.columns_1)
      this.quryLabelWidth = this.searchLabelWidth(70)
      this.quryLabelWidth2 = this.searchLabelWidth(85)
    }

  },
  mounted() {
    this.onRestWindow()
    window.addEventListener('resize',this.onRestWindow)
    this.init();
  },
  beforeDestroy() {
    window.removeEventListener('resize',this.onRestWindow)
  },
  watch: {
    // 监听路由变化
    $route(to, from) {
      if (to.name == 'todo-manage') {
        this.getDataList();
      }
      // if (to.name == "jyqxsh") {
      //   this.searchForm.type="qx";
      //   this.getDataList();
      // }
    }
  }
};
</script>

<style lang="less" scoped>
// 重构样式
/deep/ .ivu-form-item-label{
    display: flex;
    justify-content: right;
    width: 150px !important;
}
/deep/ .ivu-form-item {
    width: 100%;
    margin-bottom: 0.1rem;
    margin-right: 0 !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
/deep/ .ivu-form-item-content {
    width: 100% !important;
    margin-left: 0 ! important;
}
/deep/ .ivu-select {
    width: 100% !important;
}
/deep/ .ivu-date-picker {
    width: 100% !important;
}
/deep/ .br {
    margin-top: 15px;
    bottom: 0.12rem !important;
    .ivu-form-item-content {
        display: flex;
    }
}
/deep/ .ivu-input-type-textarea,/deep/ .ivu-input {
    height: calc(100% - 7px) !important;
}
.flex-1 {
    height: 100%;
}
/deep/ .ivu-drawer-body {
    overflow: hidden;
    .d-flex-align-center {
        height: fit-content !important;
        margin-left: 0 !important;
        justify-content: right;
        box-sizing: border-box;
        padding-right: 7px;
    }
}
.box-key {
    /deep/ .ivu-form-item-content {
        margin-left: 100px !important;
    }
}
</style>
